//
//  Dictionary+Extension.swift
//  TDDStudySwift
//
//  Created by baidu on 7/1/16.
//  Copyright © 2016 caoyuan. All rights reserved.
//

import Foundation

extension Dictionary {
    // if dict has key ,return ture
    func pyHaskey(key:Key) -> Bool {
        for k in self.keys {
            if k == key {
                return true
            }
        }
        return false
    }
    
    func forEach(block:(key:Key,value:Value)->Void) -> Void {
        for (_key,_value) in self  //无序
            
        {
            block(key:_key, value: _value)
        }
    }
    
}

extension Dictionary where Value:Equatable {
    // if dict has object return the key of object, else return nil
    func pyHasValue(object:Value) -> Key? {
        for (key, value) in self {
            if value == object {
                return key
            }
        }
        return nil
    }
}
